<script type="text/javascript">
//Obtiene lat y lng de direccion y se lo pasa a input coordenadas
		function obtiene_coordenadas(){
			var geocoder;
			geocoder = new google.maps.Geocoder();
			var direccion = document.getElementById("direccion").value;

			geocoder.geocode( { 'address': direccion}, function(results, status) {
			    if (status == google.maps.GeocoderStatus.OK) {			       
			       var coord = results[0].geometry.location;
			       //super magia de escapear para sacar los parentesis
			       var regExp = /\(([^)]+)\)/;
			       var exito = regExp.exec(coord);
			       	       
			       document.forms.datos_registro.coordenadas.value=exito[1];
	 		       document.forms.datos_registro.coordenadas.disabled="disabled";
			    } else {
			       alert("Debe indicar su direccion en el formato especificado: [numero calle, departamento, país], aviso: " + status);
			    }
			});
		 }

</script>
<form id="form" name="datos_registro" action="<?php echo site_url(array('tecnico','insertar'));?>" method="post">
	<fieldset class="form-fieldset"><legend>Datos del técnico</legend>
		<table class="form-table">
			<tr>
				<td><label>Documento:</label></td>
				<td>
					<input maxlength="8" size="25" name="documento" value="<?php echo post_value('documento');?>" class="validate[required, custom[number], minSize[8]]" />		
				</td>	
			</tr>
			<tr>
				<td><label>Nombre:</label></td>
				<td>
					<input maxlength="25" size="25" name="nombres" value="<?php echo post_value('nombres');?>" class="validate[required]"/>
				</td>	
			</tr> 
			<tr>
				<td><label>Apellido:</label></td>
				<td>
					<input maxlength="35" size="25" name="apellidos" value="<?php echo post_value('apellidos');?>" class="validate[required]"/>	
				</td>	
			</tr>	
			<tr>
				<td><label>Email:</label></td>
				<td>
					<input maxlength="35" size="25" name="email" value="<?php echo post_value('email');?>" class="validate[required,custom[email]]"/>
				</td>	
			</tr>					
			<tr>
				<td><label>Password:</label></td>
				<td>
					<input id="password" type="password" maxlength="25" size="25" name="password" class="validate[required,minSize[6]]"/>
				</td>			
			</tr>	
			<tr>
				<td><label>Repita Password:</label></td>
				<td>
					<input type="password" maxlength="25" size="25" name="cpassword" class="validate[required, minSize[6], equals[password]]"/>
				</td>
			</tr>
			<tr>
	   			<td><label for="pais_fk">Pais</label></td>
	   			<td>
					<select name="pais_fk">
						<option></option>
						<?php foreach ($paises as $pais):?>
						<option <?php if($pais['id'] == post_value('pais_fk')) echo 'selected';?> value=<?php echo $pais['id'];?>><?php echo $pais['nombre'];?></option>
						<?php endforeach;?>
					</select>
				</td>			    		
			</tr>
	   		<tr>
	   			<td><label for="departamento_fk">Departamento</label></td>
	   			<td>
					<select name="departamento_fk">
						<option></option>
						<?php foreach ($departamentos as $departamento):?>
						<option <?php if($departamento['id'] == post_value('departamento_fk')) echo 'selected';?> value=<?php echo $departamento['id'];?>><?php echo $departamento['nombre'];?></option>
						<?php  endforeach;?>
					</select>
				</td>		    		
			</tr>
			<tr>
				<td><label>Barrio:</label></td>
				<td>
					<input maxlength="35" size="25" name="barrio" value="<?php echo post_value('barrio');?>"/>
				</td>	
			</tr>
			<tr>
			<td><label>Direccion:</label></td>
			<td><input maxlength="35" id="direccion" size="25" type="text" name="direccion" class="validate[required]" value="Formato:    numero calle, departamento, país" onclick="document.forms.datos_registro.direccion.value= ''"/></td>	
			
				
			</tr>
			<tr>
				<td><label>Celular:</label></td>
				<td>
					<input maxlength="35" size="25" name="celular" value="<?php echo post_value('celular');?>"/>
				</td>	
			</tr>
			<tr>
			<td><label>Coordenadas:</label></td>
			<td><input maxlength="35" size="25" name="coordenadas"  onclick="obtiene_coordenadas()" value="Una vez ingresada la direccion, CLICK AQUI para obtener sus coordenadas" readonly="readonly"/></td>
				
			</tr>
		</table>
	</fieldset>
	
	<div style="height: 20px;"></div>
	
	<fieldset class="form-fieldset"><legend>Servicios que brinda</legend>
		<table class=grid-table>			
				<thead>
					<tr>
						<th></th>
						<th>Nombre Servicio</th>
						<th>Precio por Hora</th>
					</tr>
				</thead>
				<?php foreach($tipos_servicio as $lista_s):?>
				<tbody>				
					<tr>
						<td><input type="checkbox" name="chk_group[]" value="<?php echo $lista_s['id'];?>" onclick="habilitarDeshabilitarPrecio(this);"> </td>
						<td><?php echo $lista_s['nombre'];?></td>
						<td> <input disabled="disabled" id="<?php echo $lista_s['id'];?>" maxlength="10" type="text" name="<?php echo 'precioHora' . $lista_s['id'];?>"> </td>
					</tr>
				</tbody>					
				<?php endforeach;?>
			
		</table>
	</fieldset>
	
	<table class="buttons-table">
		<tr>
			<td>
				<a class="button-image" href="<?php echo site_url(array('tecnico'));?>">
		      		<img title="Volver" alt="Volver" src="<?php echo site_url(array('web', 'img', 'icon-back.png'));?>"/>
		      		<label>Volver</label>
		      	</a>
		      	
		      	<a id="submit" class="button-image" href="#">
		      		<img title="Guardar" alt="Guardar" src="<?php echo site_url(array('web', 'img', 'icon-check.png'));?>"/>
		      		<label>Guardar</label>
		      	</a>
		   	</td>
		</tr> 
	</table>
</form>

<script type="text/javascript">

	function habilitarDeshabilitarPrecio(obj)
	{
		if (obj.checked){
			$('#' + obj.value).prop('disabled', false);
			$('#' + obj.value).addClass('validate[required, custom[number]]');
		}
		else{
			$('#' + obj.value).prop('disabled', true);
			$('#' + obj.value).removeClass('validate[required, custom[number]]');
		}
	}
</script>